package com.webside.wap.common.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webside.util.PageUtil;
import com.webside.wap.common.mapper.BSeriesMapper;
import com.webside.wap.common.model.BSeries;
import com.webside.wap.common.service.BSeriesService;
@Service("BSeriesServiceimpl")
public class BSeriesServiceImpl implements BSeriesService {
	@Autowired
	private BSeriesMapper bSeriesDao;
	
	/**
	 * 获取搜索集合
	 * @param BSeries bSeries
	 * @param PageUtil pageUtil
	 * @param String sort
	 */
	public List<BSeries> SearchSeriesByPageVo(BSeries bSeries, PageUtil pageUtil, String sort) {
		if (pageUtil!=null) {
			pageUtil.setPageSize(8);
			pageUtil.setPageNum((pageUtil.getPageNum()-1)*pageUtil.getPageSize());
		}else {
			pageUtil=new PageUtil();
			pageUtil.setPageNum(1);
			pageUtil.setPageSize(8);
		}
		int beginSize = pageUtil.getPageNum()*pageUtil.getPageSize()+1;
		return bSeriesDao.searchSeriesByPageVo(bSeries, pageUtil,beginSize, sort);
	}

	/**
	 * 获取首页各分类集合
	 * @param BSeries bSeries
	 */
	public List<BSeries> selectIndexMovieByKind(BSeries bSeries) {

		return bSeriesDao.selectIndexMovieByKind(bSeries);
	}
	
	/**
     * 根据条件查询电影
     * 并分页
     * （此接口和SearchSeriesByPageVo接口功能可能是重合的
     * 	重构时为了降低修改复杂度暂时延用）
     * @param BSeries bSeries
	 * @param PageUtil pageUtil
	 * @param String sort
     * @return
     */
	public List<BSeries> findBSeriesByPageVo(BSeries bSeries, PageUtil pageUtil, String sort) {
		int beginSize=0;
		if (pageUtil!=null) {
			pageUtil.setPageSize(8);
			beginSize = (pageUtil.getPageNum()-1)*pageUtil.getPageSize();
		}else {
			pageUtil=new PageUtil();
			pageUtil.setPageSize(8);
		}
		
		System.out.println("beginSize:"+beginSize);
		return bSeriesDao.searchSeriesByPageVo(bSeries, pageUtil,beginSize, sort);
	}
	
	/**
	  * 根据BSeries条件构建的BSeries对象返回记录数
	  * @param bSeries
	  * @return
	  */
	public int getProductsCount(BSeries bSeries) {
		return bSeriesDao.getProductsCount(bSeries);
	}
	
	 /**
     * 通过id查询剧集
     * @param id
     * @return
     */
	public List<BSeries> selectSeriesById(Integer id) {
		return  bSeriesDao.selectByPrimaryKey(id);
	}

	public List<BSeries> selectMayLike(BSeries bSeries) {
		return bSeriesDao.selectMayLike(bSeries);
	}

}
